package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.CustomerTraceHistory;
import cn.wolfcode.crm.domain.Employee;
import cn.wolfcode.crm.mapper.CustomerTraceHistoryMapper;
import cn.wolfcode.crm.qo.QueryObject;
import cn.wolfcode.crm.service.ICustomerTraceHistoryService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CustomerTraceHistoryServiceimpl implements ICustomerTraceHistoryService {

    @Autowired
    private CustomerTraceHistoryMapper customerTraceHistoryMapper;

    @Override
    public void save(CustomerTraceHistory customerTraceHistory) {
        //获得当前用户
        Employee employee = (Employee) SecurityUtils.getSubject().getPrincipal();
        //设置录入人
        customerTraceHistory.setInputUser(employee);
        //设置录入时间
        customerTraceHistory.setInputTime(new Date());
        customerTraceHistoryMapper.insert(customerTraceHistory);
    }

    @Override
    public void deleteByPrimaryKey(Long id) {

        customerTraceHistoryMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void updateByPrimaryKey(CustomerTraceHistory customerTraceHistory) {
        customerTraceHistoryMapper.updateByPrimaryKey(customerTraceHistory);
    }

    @Override
    public CustomerTraceHistory get(Long id) {
        return customerTraceHistoryMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<CustomerTraceHistory> selectAll() {
        return customerTraceHistoryMapper.selectAll();
    }

    @Override
    public PageInfo query(QueryObject qo) {
        /*int count = customerTraceHistoryMapper.queryForCount(qo);
        if (count==0) {
            return new PageResult<CustomerTraceHistory>(qo.getPageSize());
        }*/
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<CustomerTraceHistory> list = customerTraceHistoryMapper.queryForList(qo);
        return new PageInfo(list);
    }
}
